package com.google.android.daca.util;

import com.google.android.daca.types.Option;

/**
 * A tuple representing the aggregate for an {@link Option}
 * It contains the number of positive answers and the number of negative answers
 * for the given option
 * <p><b>Note:</b> this class has a natural ordering that is inconsistent with equals.</p>
 * @author pavel
 *
 */
public class OptionAggregate implements Comparable<OptionAggregate> {
	private String optionValue;
	private int yesCount;
	private int noCount;
	/**
	 * @param yesCount
	 * @param noCount
	 */
	public OptionAggregate(String optionValue, int yesCount, int noCount) {
		this.optionValue = optionValue;
		this.yesCount = yesCount;
		this.noCount = noCount;
	}
	/**
	 * @return the yesCount
	 */
	public int getYesCount() {
		return yesCount;
	}
	/**
	 * @return the noCount
	 */
	public int getNoCount() {
		return noCount;
	}
	/**
	 * @return the option
	 */
	public String getValue() {
		return optionValue;
	}
	/* (non-Javadoc)
	 * @see java.lang.Object#hashCode()
	 */
	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + noCount;
		result = prime * result
				+ ((optionValue == null) ? 0 : optionValue.hashCode());
		result = prime * result + yesCount;
		return result;
	}
	/* (non-Javadoc)
	 * @see java.lang.Object#equals(java.lang.Object)
	 */
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (!(obj instanceof OptionAggregate))
			return false;
		OptionAggregate other = (OptionAggregate) obj;
		if (noCount != other.noCount)
			return false;
		if (optionValue == null) {
			if (other.optionValue != null)
				return false;
		} else if (!optionValue.equals(other.optionValue))
			return false;
		if (yesCount != other.yesCount)
			return false;
		return true;
	}
	@Override
	/**
	 * 
	 */
	public int compareTo(OptionAggregate another) {
		if (this.yesCount < another.yesCount) {
			return 1;
		} else if (this.yesCount > another.yesCount) {
			return -1;
		} 
		return 0;
	}
	
	
	
}
